/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view.Kasse;

import databaseHandling.KategoriHandler;
import java.awt.Dimension;
import java.awt.Point;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Kategori;
import model.Vare;

/**
 *
 * @author Jeppe
 */
public class VarePanel extends javax.swing.JPanel {

    private final KassePanel kassePanel;

    private static Point UPPER_LEFT_MARGIN = new Point(10, 80);

    /**
     * Creates new form KategoriMixPakke
     */
    public VarePanel(KassePanel kassePanel) {
        initComponents();
        this.kassePanel = kassePanel;
    }

    public void visVarerVedKategori(Kategori kategori) {
        try {
            ArrayList<Vare> vareList = KategoriHandler.hentVarerVedKategori(kategori);

            removeAll();
            add(jButton1);
            Dimension dimension = new Dimension(130, 130);

            int locationX = UPPER_LEFT_MARGIN.x;
            int locationY = -dimension.height + 70;

            for (int i = 0; i < vareList.size(); i++) {
                VareIconPanel vareIconPanel = new VareIconPanel(kassePanel, this, vareList.get(i));
                
                if (i % 2 == 0) {
                    locationX = UPPER_LEFT_MARGIN.x;

                    locationY = locationY + dimension.height + 10;
                } else {
                    locationX = UPPER_LEFT_MARGIN.x + 10 + dimension.width;
                }
                vareIconPanel.setLocation(locationX, locationY);
                vareIconPanel.setSize(dimension);
                vareIconPanel.setVisible(true);
            System.out.println("kategoriNr: " + i + " | (" + locationX + "," + locationY + ")");
                add(vareIconPanel);
                vareIconPanel.setVisible(true);
                revalidate();
                repaint();
            }
        } catch (SQLException ex) {
            Logger.getLogger(VarePanel.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(VarePanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setOpaque(false);
        setLayout(null);

        jButton1.setText("Tilbage");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        add(jButton1);
        jButton1.setBounds(10, 10, 90, 30);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        kassePanel.visKategoriPanel();
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    // End of variables declaration//GEN-END:variables
}
